goog.provide('GLL.Button');

goog.require('lime.Button');
goog.require('lime.Sprite');

/**
@param pic.xxx  up: pic.up.xxx  down pic.down.xxx disable: pic.disable.xxx
@param callback click-event function
*/
GLL.Button = function(pic_file_name, callback)
{
	this._disabled =false;
	var pos = pic_file_name.lastIndexOf(".");
	if(pos <= 0){
		lime.Button.call(this);
		return;
	}
	var file_name = pic_file_name.substr(0, pos);
	var file_fix = pic_file_name.substr(pos, pic_file_name.length);
	var up_pic = file_name + ".up" + file_fix;
	var down_pic = file_name + ".down" + file_fix;	
	var dis_pic = file_name + ".disable" + file_fix;
	this._upState = new lime.Sprite().setFill(up_pic);
	this._downState = new lime.Sprite().setFill(down_pic);
	this._disableState = new lime.Sprite().setFill(dis_pic);
	lime.Button.call(this, this._upState, this._downState);
	
	if(!goog.isDefAndNotNull(callback)){
		callback = goog.nullFunction;
	}
	goog.events.listen(this, lime.Button.Event.CLICK, callback);
	var listeners = goog.events.getListeners(this, lime.Button.Event.CLICK, false);
	this._listener = listeners[0];
};

goog.inherits(GLL.Button, lime.Button);

GLL.Button.prototype.setDisabled = function(bool_val)
{
	if(this._disabled == bool_val) return;
	this._disabled = bool_val;
	if(bool_val){
		this.setDownState(this._disableState);
		this.setUpState(this._disableState);
		goog.events.unlistenByKey(this._listener.key);
	}else{
		this.setDownState(this._downState);
		this.setUpState(this._upState);
		goog.events.listen(this, lime.Button.Event.CLICK, this._listener);
	}
}

GLL.Button.prototype.isDisabled = function(){ return this._disabled;}
